import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;

class HeroDemo extends StatelessWidget {
  final String photo;
  final VoidCallback onTap;
  final double width;

  const HeroDemo({Key key, this.photo, this.onTap, this.width}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      child: Hero(tag: photo, child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap,
          child: Image.network(photo,fit: BoxFit.contain),
        ),
      )),
    );
  }
}

class HeroAnimation extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    timeDilation = 10.0;
    return Scaffold(
      appBar: AppBar(
        title: Text('动画'),
      ),
      body: Center(
        child: HeroDemo(
          photo: "http://pic18.nipic.com/20111213/8791344_093424951000_2.jpg",
          width: 300.0,
          onTap: (){
            Navigator.of(context).push(MaterialPageRoute(builder: (context){
              return Scaffold(
                appBar: AppBar(
                  title: Text('Page'),
                ),
                body: Container(
                  color: Colors.lightBlue,
                  padding: EdgeInsets.all(10.0),
                  alignment: Alignment.topLeft,
                  child: HeroDemo(
                    photo: "http://pic18.nipic.com/20111213/8791344_093424951000_2.jpg",
                    width: 100.0,
                    onTap: (){
                      Navigator.of(context).pop();
                    },
                  ),
                ),
              );
            }));
          },
        ),
      ),
    );
  }
}

